<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="Content-Language" content="zh-cn">
    
    
    <title>
        
            原码、反码、补码、移码、浮点数 | Nefelibata
             | Nefelibata
        
    </title>
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    
        <meta name="theme-color" content="#77AAFF">
    
    
    <meta name="keywords" content="">
    
    

    

    <!-- Baidu Push -->
<script>
	(function(){
		var bp = document.createElement('script');
		var curProtocol = window.location.protocol.split(':')[0];
		if (curProtocol === 'https') {
			bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
		}
		else {
			bp.src = 'http://push.zhanzhang.baidu.com/push.js';
		}
		var s = document.getElementsByTagName("script")[0];
		s.parentNode.insertBefore(bp, s);
	})();

	var _hmt = _hmt || [];
</script>



    
    <meta name="description" content="原码、反码、补码、移码、浮点数">
<meta property="og:type" content="article">
<meta property="og:title" content="原码、反码、补码、移码、浮点数">
<meta property="og:url" content="https://nefelibata.icu/2023/09995a41cb.html">
<meta property="og:site_name" content="Nefelibata">
<meta property="og:description" content="原码、反码、补码、移码、浮点数">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://picture-0111.oss-cn-beijing.aliyuncs.com/img/20230914131854.png">
<meta property="og:image" content="https://picture-0111.oss-cn-beijing.aliyuncs.com/img/20230914132505.png">
<meta property="og:image" content="https://picture-0111.oss-cn-beijing.aliyuncs.com/img/20230914132537.png">
<meta property="og:image" content="https://picture-0111.oss-cn-beijing.aliyuncs.com/img/20230914132843.png">
<meta property="article:published_time" content="2023-09-14T05:02:23.000Z">
<meta property="article:modified_time" content="2024-01-04T02:41:48.350Z">
<meta property="article:author" content="Nefelibata">
<meta property="article:tag" content="Simple">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://picture-0111.oss-cn-beijing.aliyuncs.com/img/20230914131854.png">
    
        <link rel="alternate" type="application/atom+xml" title="Nefelibata" href="/blog/atom.xml">
    
    <link rel="shortcut icon" href="/blog/img/favicon.ico">
    <link id="style" rel="stylesheet" href="/blog/css/style.css?v=3.0">
    <script>window.lazyScripts=[]</script>

    <!-- custom head -->
    
<meta name="generator" content="Hexo 6.3.0">
<style>.github-emoji { position: relative; display: inline-block; width: 1.2em; min-height: 1.2em; overflow: hidden; vertical-align: top; color: transparent; }  .github-emoji > span { position: relative; z-index: 10; }  .github-emoji img, .github-emoji .fancybox { margin: 0 !important; padding: 0 !important; border: none !important; outline: none !important; text-decoration: none !important; user-select: none !important; cursor: auto !important; }  .github-emoji img { height: 1.2em !important; width: 1.2em !important; position: absolute !important; left: 50% !important; top: 50% !important; transform: translate(-50%, -50%) !important; user-select: none !important; cursor: auto !important; } .github-emoji-fallback { color: inherit; } .github-emoji-fallback img { opacity: 0 !important; }</style>
</head>

<body>
    <div id="loading" class="active"></div>
    <aside id="menu"  class >
  <div class="inner flex-row-vertical">
    <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menu-off">
        <i class="icon icon-lg icon-close"></i>
    </a>
    <div class="brand-wrap" >
      <div class="brand">
        <a class="avatar waves-effect waves-circle waves-light">
          <img src="/blog/img/avatar.jpg" alt="avatar">
        </a>
        <hgroup class="introduce">
          <h5 class="nickname" id="name">Nefelibata</h5>
        </hgroup>
      </div>
    </div>
    <div class="scroll-wrap flex-col">
      <ul class="nav">
        
              <li class="waves-block waves-effect">
                  <a href="/blog/" target="_self" >
                    <i class="icon icon-lg icon-home"></i>
                    <span>主 页</span><i class="icon icon-lg icon-caret-left"></i>
                  </a>
              </li>
            
              <li class="waves-block waves-effect">
                  <a href="/blog/archives" target="_self" >
                    <i class="icon icon-lg icon-archives"></i>
                    <span>归 档</span><i class="icon icon-lg icon-caret-left"></i>
                  </a>
              </li>
            
              <li class="waves-block waves-effect">
                  <a href="/blog/categories" target="_self" >
                    <i class="icon icon-lg icon-th-list"></i>
                    <span>分 类</span><i class="icon icon-lg icon-caret-left"></i>
                  </a>
              </li>
            
              <li class="waves-block waves-effect">
                  <a href="/blog/tags" target="_self" >
                    <i class="icon icon-lg icon-tags"></i>
                    <span>标 签</span><i class="icon icon-lg icon-caret-left"></i>
                  </a>
              </li>
            
              <li class="waves-block waves-effect">
                  <a href="/blog/../gallery" target="_blank" >
                    <i class="icon icon-lg icon-image"></i>
                    <span>相册</span><i class="icon icon-lg icon-caret-left"></i>
                  </a>
              </li>
            
              <li class="waves-block waves-effect">
                  <a href="/blog/../about" target="_blank" >
                    <i class="icon icon-lg icon-smile-o"></i>
                    <span>关 于</span><i class="icon icon-lg icon-caret-left"></i>
                  </a>
              </li>
            
              <li class="waves-block waves-effect">
                  <a href="/blog/../" target="_self" >
                    <i class="icon icon-lg icon-tree"></i>
                    <span>Nefelibata</span><i class="icon icon-lg icon-caret-left"></i>
                  </a>
              </li>
            
      <div class="nav2">
          
              <a class="nav2item" data-title="Email" href="mailto:kunpengl0111@gamil.com" target="_parent"title="Email" >
                <i class="icon icon-lg icon-envelope-o envelope-o"></i>
              </a>
          
              <a class="nav2item" data-title="Github" href="https://github.com/kpl0111" target="_blank"title="Github" >
                <i class="icon icon-lg icon-github github"></i>
              </a>
          
              <a class="nav2item" data-title="Twitter" href="https://twitter.com/Nefelib31847846" target="_blank"title="Twitter" >
                <i class="icon icon-lg icon-twitter twitter"></i>
              </a>
          
        </div>
      </ul>
    </div>
  </div>
</aside>


    <main id="main">
        <header class="top-header" id="header">
    <div class="flex-row">
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light on" id="menu-toggle">
          <i class="icon icon-lg icon-navicon"></i>
        </a>
        <div class="flex-col header-title ellipsis">原码、反码、补码、移码、浮点数</div>
        
        <div class="search-wrap" id="search-wrap">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="back">
                <i class="icon icon-lg icon-chevron-left"></i>
            </a>
            <input type="text" id="key" class="search-input" autocomplete="off" placeholder="输入感兴趣的关键字">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="search">
                <i class="icon icon-lg icon-search"></i>
            </a>
        </div>
        
        <a href="../../atom.xml" target="_blank" class="header-icon waves-effect waves-circle waves-light" id="Rss">
            <i class="icon icon-lg icon-rss"></i>
        </a>
    </div>
</header>
<header class="content-header post-header">
    <div class="container fade-scale">
        <div id="myheader">
            <h1 class="title">
                
            </h1>
            <h5 class="subtitle">
                
                
            </h5>
        </div>
    </div>
</header>


<div class="container body-wrap">
    
    <aside class="post-widget">
        <nav class="post-toc-wrap" id="post-toc">
            <h4>TOC</h4>
            
                <ol class="post-toc"><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5%E5%8F%8A%E8%A1%A8%E7%A4%BA%E8%8C%83%E5%9B%B4"><span class="post-toc-text">基本概念及表示范围</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#%E5%AE%9A%E4%B9%89"><span class="post-toc-text">定义</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#%E6%B5%AE%E7%82%B9%E6%95%B0"><span class="post-toc-text">浮点数</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#IEEE754%E6%A0%87%E5%87%86"><span class="post-toc-text">IEEE754标准</span></a></li></ol></li></ol></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#%E7%9B%B8%E4%BA%92%E8%BD%AC%E6%8D%A2%E4%BB%A5%E5%8F%8A%E8%BF%90%E7%AE%97"><span class="post-toc-text">相互转换以及运算</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#%E4%BA%8C%E8%BF%9B%E5%88%B6%E5%8D%81%E8%BF%9B%E5%88%B6%E8%BD%AC%E6%8D%A2"><span class="post-toc-text">二进制十进制转换</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#%E5%8E%9F%E7%A0%81%E3%80%81%E5%8F%8D%E7%A0%81%E3%80%81%E8%A1%A5%E7%A0%81%E3%80%81%E7%A7%BB%E7%A0%81%E7%9B%B8%E4%BA%92%E8%BD%AC%E6%8D%A2"><span class="post-toc-text">原码、反码、补码、移码相互转换</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#%E8%A1%A8%E7%A4%BA%E8%8C%83%E5%9B%B4"><span class="post-toc-text">表示范围</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#%E5%8A%A0%E5%87%8F%E8%BF%90%E7%AE%97"><span class="post-toc-text">加减运算</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#%E4%B9%98%E6%B3%95%E8%BF%90%E7%AE%97"><span class="post-toc-text">乘法运算</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#%E9%99%A4%E6%B3%95%E8%BF%90%E7%AE%97"><span class="post-toc-text">除法运算</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#%E7%AC%A6%E5%8F%B7%E6%89%A9%E5%B1%95"><span class="post-toc-text">符号扩展</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#%E5%AE%9A%E7%82%B9%E6%95%B0%E7%A7%BB%E4%BD%8D%E8%BF%90%E7%AE%97"><span class="post-toc-text">定点数移位运算</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#%E7%AE%97%E6%9C%AF%E7%A7%BB%E4%BD%8D"><span class="post-toc-text">算术移位</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#%E9%80%BB%E8%BE%91%E7%A7%BB%E4%BD%8D"><span class="post-toc-text">逻辑移位</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#%E5%BE%AA%E7%8E%AF%E7%A7%BB%E4%BD%8D"><span class="post-toc-text">循环移位</span></a></li></ol></li></ol></li></ol>
            
        </nav>
    </aside>
   
<article id="post-原码、反码、补码、移码、浮点数"
  class="post-article article-type-post fade" itemprop="blogPost">

    <div class="post-card">
        <h1 class="post-card-title">原码、反码、补码、移码、浮点数</h1>
        <div class="post-meta">
            <i class="icon icon-lg icon-calendar-o"></i>
            发表于
            <time class="post-time" title="2023-09-14 13:02:23" datetime="2023-09-14T05:02:23.000Z"  itemprop="datePublished">2023-09-14</time>

            <br id="mybreak"/>
            
	<i class="icon icon-lg icon-folder-o"></i>
	分类：<ul class="article-category-list"><li class="article-category-list-item"><a class="article-category-list-link" href="/blog/categories/%E7%83%82%E7%AC%94%E5%A4%B4/">烂笔头</a></li></ul>


            <i>·</i>
        </div>
        <div class="post-count-custom">
            <i class="icon icon-lg icon-comment-o"></i>
            阅读本文可能花费您&nbsp;<span class="post-count">9.9</span>&nbsp;分钟
        </div>
        <div class="post-content" id="post-content" itemprop="postContent">
            <p>原码、反码、补码、移码、浮点数</p>
<span id="more"></span>

<h2 id="基本概念及表示范围"><a href="#基本概念及表示范围" class="headerlink" title="基本概念及表示范围"></a>基本概念及表示范围</h2><h3 id="定义"><a href="#定义" class="headerlink" title="定义"></a>定义</h3><ol>
<li>真值：对于无符号数，真值即对应其十进制数值，对于有符号数，首位为符号位首位为1表示负，首位为0表示正，剩余位为对应十进制绝对值</li>
<li>原码：符号位加上真值的绝对值。即用第一位表示符号 其余位表示值。比如如果是8位二进制: +1 = 1000_0001</li>
<li>反码：正数的反码是其本身，负数的反码是在其原码的基础上符号位不变，其余各个位取反。</li>
<li>补码：正数的补码就是其本身，负数的补码是在其反码的基础上+1</li>
<li>移码：真值+偏置值，n位二进制数偏置值为$2^n - 1$,其简单计算方法为补码符号位取反，数值位不变</li>
</ol>
<h3 id="浮点数"><a href="#浮点数" class="headerlink" title="浮点数"></a>浮点数</h3><p>$V = (-1)^S * M * R^E$,如8.345 * 10^0：</p>
<ul>
<li>S：符号位，取值 0 或 1，决定一个数字的符号，0 表示正，1 表示负</li>
<li>M：尾数，用小数表示，例如前面所看到的 8.345 * 10^0，8.345 就是尾数</li>
<li>R：基数，表示十进制数 R 就是 10，表示二进制数 R 就是 2</li>
<li>E：指数，用整数表示，例如前面看到的 10^-1，-1 即是指数</li>
</ul>
<p>例如32位二进制浮点数及可表示为下列格式：</p>
<figure class="image-bubble">
                <div class="img-lightbox">
                    <div class="overlay"></div>
                    <img src="https://picture-0111.oss-cn-beijing.aliyuncs.com/img/20230914131854.png" alt="20230914131854" title="">
                </div>
                <div class="image-caption">20230914131854</div>
            </figure>

<h4 id="IEEE754标准"><a href="#IEEE754标准" class="headerlink" title="IEEE754标准"></a>IEEE754标准</h4><ul>
<li>单精度浮点数 float：32 位，符号位 S 占 1 bit，指数 E 占 8 bit，尾数 M 占 23 bit</li>
<li>双精度浮点数 float：64 位，符号位 S 占 1 bit，指数 E 占 11 bit，尾数 M 占 52 bit</li>
</ul>
<p>为了使其表示的数字范围、精度最大化，浮点数标准还对指数和尾数进行了规定：</p>
<ol>
<li>尾数 M 的第一位总是 1（因为 1 &lt;= M &lt; 2），因此这个 1 可以省略不写，它是个隐藏位，这样单精度 23 位尾数可以表示了 24 位有效数字，双精度 52 位尾数可以表示 53 位有效数字</li>
<li>指数 E 是个无符号整数，表示 float 时，一共占 8 bit，所以它的取值范围为 0 ~ 255。但因为指数可以是负的，所以规定在存入 E 时在它原本的值加上一个中间数 127，这样 E 的取值范围为 -127 ~ 128。表示 double 时，一共占 11 bit，存入 E 时加上中间数 1023，这样取值范围为 -1023 ~ 1024。</li>
</ol>
<p>除了规定尾数和指数位，还做了以下规定：</p>
<ul>
<li>指数 E 非全 0 且非全 1：规格化数字，按上面的规则正常计算</li>
<li>指数 E 全 0，尾数非 0：非规格化数，尾数隐藏位不再是 1，而是 0(M = 0.xxxxx)，这样可以表示 0 和很小的数</li>
<li>指数 E 全 1，尾数全 0：正无穷大/负无穷大（正负取决于 S 符号位）</li>
<li>指数 E 全 1，尾数非 0：NaN(Not a Number)</li>
</ul>
<figure class="image-bubble">
                <div class="img-lightbox">
                    <div class="overlay"></div>
                    <img src="https://picture-0111.oss-cn-beijing.aliyuncs.com/img/20230914132505.png" alt="20230914132505" title="">
                </div>
                <div class="image-caption">20230914132505</div>
            </figure>

<p>有了这个统一的浮点数标准，我们再把 25.125 转换为标准的 float 浮点数：</p>
<ol>
<li>整数部分：25(D) = 11001(B)</li>
<li>小数部分：0.125(D) = 0.001(B)</li>
<li>用二进制科学计数法表示：25.125(D) = 11001.001(B) = 1.1001001 * 2^4(B)</li>
</ol>
<p>所以 S = 0，尾数 M = 1.001001 = 001001(去掉1，隐藏位)，指数 E = 4 + 127(中间数) = 135(D) = 10000111(B)。填充到 32 bit 中，如下：</p>
<figure class="image-bubble">
                <div class="img-lightbox">
                    <div class="overlay"></div>
                    <img src="https://picture-0111.oss-cn-beijing.aliyuncs.com/img/20230914132537.png" alt="20230914132537" title="">
                </div>
                <div class="image-caption">20230914132537</div>
            </figure>

<h2 id="相互转换以及运算"><a href="#相互转换以及运算" class="headerlink" title="相互转换以及运算"></a>相互转换以及运算</h2><h3 id="二进制十进制转换"><a href="#二进制十进制转换" class="headerlink" title="二进制十进制转换"></a>二进制十进制转换</h3><ol>
<li><p>整数转二进制<br> 采用”除2取余，逆序排列”法：</p>
<ol>
<li>首先用2整除一个十进制整数，得到一个商和余数</li>
<li>然后再用2去除得到的商，又会得到一个商和余数</li>
<li>重复操作，一直到商为小于1时为止</li>
<li>然后将得到的所有余数全部排列起来，再将它反过来（逆序排列），切记一定要反过来！<br> 假设我们现在需要将42转为二进制，那我们怎么做呢，如下图所示：<br> <img src="https://picture-0111.oss-cn-beijing.aliyuncs.com/img/20230914132843.png" alt="20230914132843"></li>
</ol>
</li>
<li><p>小数转二进制<br> 采用”乘2取整，顺序排列”法：</p>
<ol>
<li>用2乘十进制小数，可以得到积，将积的整数部分取出</li>
<li>再用2乘余下的小数部分，又得到一个积，再将积的整数部分取出</li>
<li>重复操作，直到积中的小数部分为零，此时0或1为二进制的最后一位，或者达到所要求的精度为止</li>
</ol>
<p> 例如将0.125转换为二进制：</p>
<ol>
<li>0.125  *  2  =  0.25 ——0</li>
<li>0.25   *  2  =  0.5   ——0</li>
<li>0.5  *  2  =  1.0     ——1<br> 当小数部分为0就可以停止乘2了，然后正序排序就构成了二进制的小数部分：0.001</li>
</ol>
<p> 如果小数的整数部分有大于0的整数时，将整数部分和小数部分先单独转为二进制，再合在一起就可以了，</p>
<p> 例如：假设要将8.125 转换为二进制</p>
<ol>
<li>现将8转为二进制：得到1000</li>
<li>再将0.125转为二进制：得到0.001</li>
<li>合并后为1000.001</li>
</ol>
</li>
<li><p>二进制转十进制<br> 以小数点左边一位为0，往左位阶依次是$2^1,2^2…$，往右是$2^{-1}, 2^{-2}…$,依次相乘并加和即可</p>
</li>
</ol>
<h3 id="原码、反码、补码、移码相互转换"><a href="#原码、反码、补码、移码相互转换" class="headerlink" title="原码、反码、补码、移码相互转换"></a>原码、反码、补码、移码相互转换</h3><table>
<thead>
<tr>
<th align="center"></th>
<th align="center">原码</th>
<th align="center">反码</th>
<th align="center">补码</th>
<th align="center">移码</th>
</tr>
</thead>
<tbody><tr>
<td align="center">正整数</td>
<td align="center">本身，符号位为0</td>
<td align="center">与原码相同</td>
<td align="center">与原码相同</td>
<td align="center">符号位取反</td>
</tr>
<tr>
<td align="center">负整数</td>
<td align="center">本身，符号位为1</td>
<td align="center">符号位不变，数值位按位取反</td>
<td align="center">反码末位加1</td>
<td align="center">符号位取反</td>
</tr>
<tr>
<td align="center">正小数</td>
<td align="center">本身，符号位为0</td>
<td align="center">与原码相同</td>
<td align="center">与原码相同</td>
<td align="center">小数无移码</td>
</tr>
<tr>
<td align="center">负小数</td>
<td align="center">本身，符号位为1</td>
<td align="center">符号位不变，数值位按位取反</td>
<td align="center">反码末位加1</td>
<td align="center">小数无移码</td>
</tr>
</tbody></table>
<h3 id="表示范围"><a href="#表示范围" class="headerlink" title="表示范围"></a>表示范围</h3><p>设有一个n位二进制数</p>
<table>
<thead>
<tr>
<th align="center"></th>
<th align="center">表示范围（机器字长为n + 1）</th>
<th align="center">特征</th>
</tr>
</thead>
<tbody><tr>
<td align="center">整数原码</td>
<td align="center">$-（2^n -1）\le x \le 2^n - 1$</td>
<td align="center">0的表示方法有两种,原点对称</td>
</tr>
<tr>
<td align="center">小数原码</td>
<td align="center">$-(1 - 2^{-n}) \le x \le 1 - 2^{-n}$</td>
<td align="center">0的表示方法有两种,原点对称</td>
</tr>
<tr>
<td align="center">整数反码</td>
<td align="center">$-（2^n -1）\le x \le 2^n - 1$</td>
<td align="center">0的表示方法有两种,原点对称</td>
</tr>
<tr>
<td align="center">小数反码</td>
<td align="center">$-(1 - 2^{-n}) \le x \le 1 - 2^{-n}$</td>
<td align="center">0的表示方法有两种,原点对称</td>
</tr>
<tr>
<td align="center">整数补码</td>
<td align="center">$- 2^n \le x \le 2^n - 1$</td>
<td align="center">真值0只有一种形式，并规定1000，0000表示$x = -2^7$</td>
</tr>
<tr>
<td align="center">小数补码</td>
<td align="center">$-1 \le x \le 1 - 2^{-n}$</td>
<td align="center">真值0只有一种格式，规定1.000，0000表示x = -1</td>
</tr>
<tr>
<td align="center">整数移码</td>
<td align="center">$- 2^n \le x \le 2^n - 1$</td>
<td align="center">移码只能用于表示整数，0同样只有一种表示形式，很容易对比大小，移码表示数依次真值递增</td>
</tr>
</tbody></table>
<p>在现代计算机中，通常用<strong>定点补码表示整数</strong> ，用<strong>定点原码表示小数</strong> ，用<strong>移码表示浮点数的阶码</strong></p>
<h3 id="加减运算"><a href="#加减运算" class="headerlink" title="加减运算"></a>加减运算</h3><p>原码加减：</p>
<ul>
<li>原码加减比较麻烦，一般采用补码进行运算</li>
</ul>
<p>补码加减：</p>
<ul>
<li>直接相加并进位</li>
<li>减法等同于加上负数，</li>
<li>由$[x]<em>{补}$ 求$[-x]</em>{补}$，将所有位取反，末尾加一</li>
</ul>
<h3 id="乘法运算"><a href="#乘法运算" class="headerlink" title="乘法运算"></a>乘法运算</h3><ol>
<li>原码：符号位和数值位单独运算</li>
<li>补码：待补充</li>
</ol>
<h3 id="除法运算"><a href="#除法运算" class="headerlink" title="除法运算"></a>除法运算</h3><p>待补充</p>
<h3 id="符号扩展"><a href="#符号扩展" class="headerlink" title="符号扩展"></a>符号扩展</h3><ol>
<li>正数（原、反、补码都一样）最高位进行扩展</li>
<li>负数<ol>
<li>原码：在符号位和数值位之间补0</li>
<li>反码：在符号位和数值位之间补1</li>
<li>补码：在符号位和数值位之间补1</li>
</ol>
</li>
<li>正小数（原、反、补码都一样）末尾进行0扩展</li>
<li>负小数<ol>
<li>原码：末尾补0</li>
<li>反码：末位补1</li>
<li>补码：末位补0</li>
</ol>
</li>
</ol>
<h3 id="定点数移位运算"><a href="#定点数移位运算" class="headerlink" title="定点数移位运算"></a>定点数移位运算</h3><h4 id="算术移位"><a href="#算术移位" class="headerlink" title="算术移位"></a>算术移位</h4><ol>
<li>原码：符号位不参与移位，左移右移都补0</li>
<li>反码：符号位不参与移位，左移右移都补1</li>
<li>补码：符号位不参与移位，左移补0，右移补1</li>
</ol>
<h4 id="逻辑移位"><a href="#逻辑移位" class="headerlink" title="逻辑移位"></a>逻辑移位</h4><p>可看作对无符号数的移位</p>
<h4 id="循环移位"><a href="#循环移位" class="headerlink" title="循环移位"></a>循环移位</h4><p>循环补位，注意进位位</p>

        </div>

        <blockquote class="post-copyright">
    <div class="content">
        
<span class="post-time">
    最后更新：<time datetime="2024-01-04T02:41:48.350Z" itemprop="dateUpdated">2024-01-04 10:41:48</time>
</span>


        
        
        
    </div>
    <footer>
        <div onclick="location.href='https://nefelibata.icu'">
            <img src="/blog/img/avatar.jpg" alt="Nefelibata">
            <a>Nefelibata</a>
        </div>
    </footer>
</blockquote>

        
    <div class="page-reward">
        <nav class="myreward">
            <a id="rewardBtn" href="javascript:;"><span>打&nbsp;赏</span><span>装成好像很多人打赏的样子</span></a>
        </nav>
    </div>



        <div class="post-footer">
            

            
<div class="page-share-wrap">
    

<div class="page-share" id="pageShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=https://nefelibata.icu/2023/09995a41cb.html&title=《原码、反码、补码、移码、浮点数》 — Nefelibata&pic=https://nefelibata.icu/img/avatar.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=https://nefelibata.icu/2023/09995a41cb.html&title=《原码、反码、补码、移码、浮点数》 — Nefelibata&source=原码、反码、补码、移码、浮点数" data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=https://nefelibata.icu/2023/09995a41cb.html" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《原码、反码、补码、移码、浮点数》 — Nefelibata&url=https://nefelibata.icu/2023/09995a41cb.html&via=https://nefelibata.icu" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=https://nefelibata.icu/2023/09995a41cb.html" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>



    <a href="javascript:;" id="shareFab" class="page-share-fab waves-effect waves-circle">
        <i class="icon icon-share-alt icon-lg"></i>
    </a>
</div>



        </div>
    </div>

    
<nav class="post-nav flex-row flex-justify-between">
  
    <div class="waves-block waves-effect prev">
      <a href="/blog/2023/119fca6f5f.html" id="post-prev" class="post-nav-link">
        <h4 class="title" >
          上一篇：厨子戏子痞子观感
        </h4>
      </a>
    </div>
  

  
    <div class="waves-block waves-effect next">
      <a href="/blog/2023/044b8db958.html" id="post-next" class="post-nav-link">
        <h4 class="title" data-hover="下一篇：Git常用指令">下一篇：Git常用指令</h4>
      </a>
    </div>
  
</nav>


</article>

</div>

        <footer class="footer">
    <div class="footer-content">
        <span class="power">
            <i class="icon icon-lg icon-copyright"></i>
            2021
            <i class="icon icon-lg icon-heart"></i>
            <a href="https://nefelibata.icu">nefelibata.icu</a>
        </span>
    </div>
</footer>

    </main>
    
        
<div id="reward" class="page-modal reward-lay">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <h3 class="reward-title">
        <i class="icon icon-quote-left"></i>
        <span>感谢您的鼓励支持！</span>
        <i class="icon icon-quote-right"></i>
    </h3>
    <div class="reward-content">
        
        <div class="reward-code">
            <img id="rewardCode" data-img="/blog/img/dog.png" alt="打赏二维码">
        </div>
        
        <label class="reward-toggle">
            <input id="rewardToggle" type="checkbox" class="reward-toggle-check"
                data-wechat="/blog/img/wechat.png" data-alipay="/blog/img/alipay.png">
            <div class="reward-toggle-ctrol">
                <span class="reward-toggle-item wechatPay">&nbsp;&nbsp;微信&nbsp;&nbsp;</span>
                <span class="reward-toggle-item alipayPay">支付宝</span>
            </div>
        </label>
        
        <i class="icon icon-caret-up"></i>
    </div>
</div>


    
    <div class="mask" id="mask"></div>
<a href="javascript:;" id="gotop" class="waves-effect waves-circle waves-light"><span class="icon icon-lg icon-chevron-up"></span></a>



<div class="global-share" id="globalShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=https://nefelibata.icu/2023/09995a41cb.html&title=《原码、反码、补码、移码、浮点数》 — Nefelibata&pic=https://nefelibata.icu/img/avatar.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=https://nefelibata.icu/2023/09995a41cb.html&title=《原码、反码、补码、移码、浮点数》 — Nefelibata&source=原码、反码、补码、移码、浮点数" data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=https://nefelibata.icu/2023/09995a41cb.html" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《原码、反码、补码、移码、浮点数》 — Nefelibata&url=https://nefelibata.icu/2023/09995a41cb.html&via=https://nefelibata.icu" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=https://nefelibata.icu/2023/09995a41cb.html" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>


<div class="page-modal wx-share" id="wxShare">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <p class="wechatshare">扫一扫，分享到微信</p>
    <img src="" alt="微信分享二维码">
</div>




    <!-- waves按钮特效 -->
<script src="//cdn.bootcss.com/node-waves/0.7.4/waves.min.js"></script>

<!-- 主题配置脚本 -->
<script>
var BLOG = { ROOT: '/blog/', SHARE: true, REWARD: true };
</script>

<!-- jquery -->
<script src="/blog/js/jquery.min.js?v=3.0"></script>

<!-- 搜索 -->

<div class="search-panel" id="search-panel">
    <ul class="search-result" id="search-result"></ul>
</div>
<template id="search-tpl">
<li class="item waves-block waves-effect" onclick="location.href='{path}'">
    <div class="title ellipsis" title="{title}">{title}</div>
</li>
</template>


<!-- main博客脚本 -->
<script src="/blog/js/main.min.js?v=3.0" ></script>

<!-- 动画&配置 -->
<script src="/blog/js/script.min.js?v=3.0" ></script>

<!-- 脚本管理 -->
<script>

if(window.innerWidth > 800){
	/* 3D标题 */
	$(".content-header").on("mousemove", threedee);

	/* 底部追随鼠标 */
	$(".footer").hover(2);

	/* gotop键的涟漪 */
	$("#gotop").hover(1);

	/* 赞赏的粒子雨 */
	$("#reward").hover(3);

	/* 微信公众号的底部渲染 */
	$("#wechat").hover(4);

    /* 标题跳动 */
    $(".archivestitle").bumpyText();

	/* 图片点击放大 */
	const postimg = jQuery(".post-content img:not(.github-emoji)");
	postimg.on("click",function(){

		mask.classList.add("in");
		main.classList.add("Mask");
		menu.classList.add("Mask");
		var myimg = this.cloneNode(true);
		myimg.classList.add("imgShow");

		setTimeout(function(){
			jQuery(myimg).animate({
				opacity:"1"
			},1000);
		},0);

		document.body.appendChild(myimg);

		myimg.onclick=function(){
			document.body.removeChild(myimg);
			mask.classList.remove("in");
			main.classList.remove("Mask");
			menu.classList.remove("Mask");
		};

	});

}

/* 名字跳动 */
$("#name").bumpyText();


/* 网站运行时间 */
// setInterval(function () {
// 	setTime("2021/3/27");
// }, 1000);

/* 文章块的淡出 */
postshow();

/* 座右铭 */
// 
//    getHitokoto();
// 


/* 粘贴提示 */
G($(".post-content"), location.href, "Nefelibata");


/* 控制台 */
if (window.console && window.console.log) {
	setTimeout(function () {
		console.log("\n %c Nefelibata %c  © kpl0111  http://nefelibata.icu \n\n", "color:#FFFFFB;background:#1abc9c;padding:5px 0;border-radius:.5rem 0 0 .5rem;", "color:#FFFFFB;background:#080808;padding:5px 0;border-radius:0 .5rem .5rem 0;");
	}, 0);
}

</script>




<!-- 公式渲染 -->

<!-- mathjax config similar to math.stackexchange -->

<script type="text/x-mathjax-config">
MathJax.Hub.Config({
    tex2jax: {
        inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
        processEscapes: true,
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
    }
});

MathJax.Hub.Queue(function() {
    var all = MathJax.Hub.getAllJax(), i;
    for(i=0; i < all.length; i += 1) {
        all[i].SourceElement().parentNode.className += ' has-jax';
    }
});
</script>

<script async src="//cdn.bootcss.com/mathjax/2.7.0/MathJax.js?config=TeX-MML-AM_CHTML" async></script>



<!-- 不蒜子 -->
<!--  -->

</body>
</html>
